let staff_index_set = new Set()
let isFirstTime = 0;
let mission_index_set = new Set()
let staff_id_set = new Set()
let mission_id_set = new Set()
let cancelMissionList = new Set()

let firstTime;
let data = [
    {
        text: 'SUMMARY',
        children: [
            {
                order: 1,
                text: 'All Today Mission'
            },
            {
                order: 2,
                text: 'All Tomorrow Mission'
            }
        ]
    },

    {
        text: 'ASSIGN MANAGEMENT',

        children: [
            {
                order: 3,
                text: 'ASSIGNED LIST'
            },
            {
                order: 9,
                text: 'UNASSIGNED LIST'
            }
        ]
    },

    {
        text: 'REPOSITORY',
        children: [
            {
                order: 5,
                text: 'STAFF LIST'
            },
            {
                order: 6,
                text: 'MISSION LIST'
            }
        ]
    }, {
        text: 'ACCOUNT',
        state: 'open',
        children: [
            {
                order: 7,
                text: 'ACCOUNT INFORMATION'
            },
            {
                order: 8,
                text: 'LOG OUT'
            }
        ]
    }
];


$('#sm').sidemenu({
    data: data,
    width: 240,
    multiple: false,
    onSelect: function (item) {
        switch (item.order) {
            case 1: {
                $('#tt').tabs('enableTab', item.text)
                $('#tt').tabs('select', item.text)
                break
            }
            case 2: {
                $('#tt').tabs('enableTab', item.text)
                $('#tt').tabs('select', item.text)
                break
            }
            case 3: {
                $('#tt').tabs('enableTab', item.text)
                $('#tt').tabs('select', item.text)
                break
            }
            case 4: {
                $('#tt').tabs('enableTab', item.text)
                $('#tt').tabs('select', item.text)
                break
            }
            case 5: {
                $('#tt').tabs('enableTab', item.text)
                $('#tt').tabs('select', item.text)
                break
            }
            case 6: {
                $('#tt').tabs('enableTab', item.text)
                $('#tt').tabs('select', item.text)
                break
            }
            case 7: {
                $('#tt').tabs('enableTab', item.text)
                $('#tt').tabs('select', item.text)
                break
            }

            case 8: {
                $.post('/common/adminLogOut',null,
                    (res)=>{
                        if (res.code == '449') {

                            alert(res.description)
                            document.location="/public/index.html"
                        } else {
                            alert(res.description)
                            document.location="/public/index.html"
                        }
                    }
                )
                document.location = "/public/index.html"
                break
            }
            case 9: {
                $('#tt').tabs('enableTab', item.text)
                $('#tt').tabs('select', item.text)
                break
            }
        }
    }
});

$('#tt').tabs(
    {
        onBeforeClose: function (title, index) {
            $('#tt').tabs(
                'disableTab', title
            )
            return false
        },
        onSelect: function (title, index) {
            if (title == 'All Today Mission') {
                document.getElementById("helpInformation").innerText = "select row for detail"
                $.post('/admin/selectTodayAllMission', null, (res) => {
                    if (res.code == '449') {
                        alert(res.description)
                        document.location="/public/index.html"
                    } else {
                        let todayMission = res.data;
                        $('#dg').datagrid({
                            data: todayMission,
                            fitColumns: true,
                            striped: true,
                            singleSelect: true,
                            nowrap: false,
                            /*
                            *   <tr>
                            <th data-options="field:'mission_id',resizable:false" >MISSION ID</th>
                            <th data-options="field:'priority',resizable:false" >PRIORITY</th>
                            <th data-options="field:'mission_name',align:'right',resizable:false" width="15%">MISSION NAME</th>
                            <th data-options="field:'deadline',align:'right',resizable:false">DEADLINE</th>
                            <th data-options="field:'staff_id',resizable:false">STAFF ID</th>
                            <th data-options="field:'name',align:'center',resizable:false" width="15%">STAFF NAME</th>
                            <th data-options="field:'status',align:'center',resizable:false">STATUS</th>
                        </tr>*/
                            columns:
                                [[
                                    {
                                        field: 'mission_id', title: 'MISSION ID'
                                    }, {
                                        field: 'priority', title: 'PRIORITY'
                                    }, {
                                        field: 'mission_name', title: 'MISSION NAME'
                                    }, {
                                        field: 'deadline', title: 'DEADLINE', sortable: true
                                    }, {
                                        field: 'staff_id', title: 'STAFF ID', sortable: true
                                    }, {
                                        field: 'name', title: 'STAFF NAME'
                                    }, {
                                        field: 'status', title: 'STATUS'
                                    },
                                ]]
                        });
                        if (isFirstTime == 0) {
                            $('#tt').tabs('select', 6)
                            isFirstTime++;
                        }
                    }
                }, 'json')
            }
            if (title == 'All Tomorrow Mission') {
                document.getElementById("helpInformation").innerText = "select row for detail"
                $.post('/admin/selectTomorrowAllMission', null, (res) => {
                    let tomorrowMission = res.data;
                    $('#dg2').datagrid({
                        data: tomorrowMission,
                        fitColumns: true,
                        striped: true,
                        singleSelect: true,
                        nowrap: false,
                        /*
                        *   <tr>
                        <th data-options="field:'mission_id',resizable:false" >MISSION ID</th>
                        <th data-options="field:'priority',resizable:false" >PRIORITY</th>
                        <th data-options="field:'mission_name',align:'right',resizable:false" width="15%">MISSION NAME</th>
                        <th data-options="field:'deadline',align:'right',resizable:false">DEADLINE</th>
                        <th data-options="field:'staff_id',resizable:false">STAFF ID</th>
                        <th data-options="field:'name',align:'center',resizable:false" width="15%">STAFF NAME</th>
                        <th data-options="field:'status',align:'center',resizable:false">STATUS</th>
                    </tr>*/
                        columns:
                            [[
                                {
                                    field: 'mission_id', title: 'MISSION ID'
                                }, {
                                    field: 'priority', title: 'PRIORITY'
                                }, {
                                    field: 'mission_name', title: 'MISSION NAME'
                                }, {
                                    field: 'deadline', title: 'DEADLINE', sortable: true
                                }, {
                                    field: 'staff_id', title: 'STAFF ID', sortable: true
                                }, {
                                    field: 'name', title: 'STAFF NAME'
                                }, {
                                    field: 'status', title: 'STATUS'
                                },
                            ]]
                    });


                }, 'json')
            }
            if (title == 'STAFF LIST') {
                document.getElementById("helpInformation").innerText = "select row for detail"
                $.post('/admin/selectAllStaff', null, (res) => {
                    let AllStaff = res.data;
                    $('#dg4').datagrid({
                        data: AllStaff,
                        striped: true,
                        nowrap: false,
                        fitColumns: true,
                        toolbar: '#tb4',
                        singleSelect: false,
                        checkbox: true,
                        checkOnSelect: true,
                        selectOnCheck: true,
                        /*
                        *   <tr>
                        <th data-options="field:'mission_id',resizable:false" >MISSION ID</th>
                        <th data-options="field:'priority',resizable:false" >PRIORITY</th>
                        <th data-options="field:'mission_name',align:'right',resizable:false" width="15%">MISSION NAME</th>
                        <th data-options="field:'deadline',align:'right',resizable:false">DEADLINE</th>
                        <th data-options="field:'staff_id',resizable:false">STAFF ID</th>
                        <th data-options="field:'name',align:'center',resizable:false" width="15%">STAFF NAME</th>
                        <th data-options="field:'status',align:'center',resizable:false">STATUS</th>
                    </tr>*/
                        columns:
                            [[{
                                field: 'ck', title: 'CHOOSE',
                                checkbox: true
                            },
                                {
                                    field: 'id', title: 'STAFF ID', width: '33%',
                                    align: 'center'
                                }, {
                                    field: 'name', title: 'STAFF NAME', align: 'center', width: '33%'
                                }, {
                                    field: 'email', title: 'STAFF EMAIL', align: 'center', width: '33%'
                                }
                            ]]
                    });
                    for (const staffSetElement of staff_index_set) {
                        $('#dg4').datagrid('selectRow', staffSetElement)
                    }

                }, 'json')

            }
            6
            if (title == 'MISSION LIST') {
                $.post('/admin/selectAllMission', null, (res) => {
                    let allMission = res.data;
                    $('#dg5').datagrid({
                        data: allMission,
                        striped: true,
                        nowrap: false,
                        toolbar: '#tb5',
                        singleSelect: false,
                        fitColumns: true,
                        checkbox: true,
                        checkOnSelect: true,
                        selectOnCheck: true,
                        columns:
                            [[{
                                field: 'ck', title: 'CHOOSE',
                                checkbox: true
                            },
                                {
                                    field: 'mission_id', title: 'MISSION ID', width: '8%', editor: {
                                        type: 'textbox'
                                        , options: {

                                            readonly: true
                                        }
                                    }
                                },
                                {
                                    field: 'mission_name', title: 'MISSION NAME', width: '18%', editor: {
                                        type: 'textbox'
                                    }
                                },
                                {
                                    field: 'content', title: 'MISSION CONTENT', width: '20%', editor: {
                                        type: 'textbox'
                                    }
                                }, {
                                    field: 'priority', title: 'PRIORITY', width: '15%', editor: {
                                        type: 'combobox',
                                        options: {
                                            valueField: 'priority',
                                            textField: 'priorityname',
                                            method: 'get',
                                            url: '/public/javascripts/priority.json',
                                            required: true
                                        }
                                    }
                                },
                                {
                                    field: 'deadline', title: 'DEADLINE', width: '20%', editor: {
                                        type: 'datetimebox'
                                        }

                                }, {
                                    field: 'mission_type', title: 'TYPE', width: '15%', editor: {
                                        type: 'combobox',
                                        options: {
                                            valueField: 'type',
                                            textField: 'typename',
                                            method: 'get',
                                            url: '/public/javascripts/type.json',
                                            required: true
                                        }
                                    }
                                }
                            ]]
                    });
                    for (const staffSetElement of mission_index_set) {
                        $('#dg5').datagrid('selectRow', staffSetElement)
                    }
                }, 'json')


            }
            if (title == 'ACCOUNT INFORMATION') {
                $.post('/admin/catAdminAccount', null, (res) => {
                    document.getElementById("_easyui_textbox_input1").value = res[0].id
                    document.getElementById("_easyui_textbox_input2").value = res[0].name
                    document.getElementById("_easyui_textbox_input3").value = res[0].address
                    document.getElementById("_easyui_textbox_input4").value = res[0].email
                    Cookies.set("staffemail",res[0].email)
                    Cookies.set("staffname",res[0].name)
                }, 'json')

            }
            if (title == 'ASSIGNED LIST') {
                $.post('/admin/selectAssignedMission', null, (res) => {
                    let assignedMission = res.data
                    $('#dg3').datagrid({
                        data: assignedMission,
                        striped: true,
                        nowrap: false,
                        fitColumns: true,
                        toolbar: '#tb3',
                        singleSelect: false,
                        checkbox: true,
                        checkOnSelect: true,
                        selectOnCheck: true,
                        /*
                        *   <tr>
                        <th data-options="field:'mission_id',resizable:false" >MISSION ID</th>
                        <th data-options="field:'priority',resizable:false" >PRIORITY</th>
                        <th data-options="field:'mission_name',align:'right',resizable:false" width="15%">MISSION NAME</th>
                        <th data-options="field:'deadline',align:'right',resizable:false">DEADLINE</th>
                        <th data-options="field:'staff_id',resizable:false">STAFF ID</th>
                        <th data-options="field:'name',align:'center',resizable:false" width="15%">STAFF NAME</th>
                        <th data-options="field:'status',align:'center',resizable:false">STATUS</th>
                    </tr>*/
                        columns:
                            [[{
                                field: 'ck', title: 'CHOOSE',
                                checkbox: true
                            },
                                /*  ,{"mission_id":13,"staff_id":10246,"staff_name":"爱荷华·亚历山大亚大爱华·亚历山大爱荷华·亚历山大爱荷华·亚历山大爱荷华·亚历山大","content":"买5斤菠萝回来",
                                "priority":"普通","mission_name":"买菠hahaha买萝haha买萝haha",
                                "deadline":"2020-06-20 08:00:00","status":0}
                                ,{"mission_id":14,"staff_id":10246,"staff_name":"爱荷华·亚历山大亚大爱华·亚历山大爱荷华·亚历山大爱荷华·亚历山大爱荷华·亚历山大","content":"买5斤萝卜回来","priority":"普通","mission_name":"买菠hahaha买萝haha买萝haha","deadline":"2020-06-20 08:00:00","status":0},{"mission_id":15,"staff_id":10246,"staff_name":"爱荷华·亚历山大亚大爱华·亚历山大爱荷华·亚历山大爱荷华·亚历山大爱荷华·亚历山大","content":"买5斤韭菜回来","priority":"普通","mission_name":"买菠hahaha买萝haha买萝haha","deadline":"2020-06-20 08:00:00","status":0},{"mission_id":16,"staff_id":10246,
                                      "staff_name":"爱荷华·亚历山大亚大爱华·亚历山大爱荷华·亚历山大爱荷华·亚历山大爱荷华·亚历山大",
                                      "content":"买5斤西瓜回来","priority":"普通","mission_name":"买菠hahaha买萝haha买萝haha",
                                      "deadline":"2020-06-21 14:09:34","status":0
                          }*/
                                {
                                    field: 'mission_id', title: 'MISSION ID', width: '5%',
                                    align: 'center'
                                },
                                {
                                    field: 'mission_name', title: 'MISSION NAME', width: '20%',
                                    align: 'center'
                                },
                                {
                                    field: 'staff_id', title: 'STAFF ID', width: '15%',
                                    align: 'center'
                                },
                                {
                                    field: 'staff_name', title: 'STAFF NAME', width: '10%',
                                    align: 'center'
                                },
                                {
                                    field: 'priority', title: 'PRIORITY', align: 'center', width: '10%',
                                },
                                {
                                    field: 'deadline', title: 'DEADLINE', align: 'center', width: '15%',
                                },
                                {
                                    field: 'email', title: 'STAFF EMAIL', align: 'center', width: '15%',
                                },
                                {
                                    field: 'status', title: 'STATUS', align: 'center', width: '10%',
                                },
                            ]]
                    });
                }, 'json')

            }
            if (title == 'UNASSIGNED LIST') {
                $.post('/admin/selectUnAssignedMission', null, (res) => {
                    let unAssignedMission = res.data
                    $('#dg6').datagrid({
                        data: unAssignedMission,
                        striped: true,
                        nowrap: false,
                        singleSelect: false,
                        checkbox: true,
                        fitColumns: true,
                        checkOnSelect: true,
                        selectOnCheck: true,
                        /*
                        *   <tr>
                        <th data-options="field:'mission_id',resizable:false" >MISSION ID</th>
                        <th data-options="field:'priority',resizable:false" >PRIORITY</th>
                        <th data-options="field:'mission_name',align:'right',resizable:false" width="15%">MISSION NAME</th>
                        <th data-options="field:'deadline',align:'right',resizable:false">DEADLINE</th>
                        <th data-options="field:'staff_id',resizable:false">STAFF ID</th>
                        <th data-options="field:'name',align:'center',resizable:false" width="15%">STAFF NAME</th>
                        <th data-options="field:'status',align:'center',resizable:false">STATUS</th>
                    </tr>*/
                        columns:
                            [[
                                /*  ,{"mission_id":13,"staff_id":10246,"staff_name":"爱荷华·亚历山大亚大爱华·亚历山大爱荷华·亚历山大爱荷华·亚历山大爱荷华·亚历山大","content":"买5斤菠萝回来",
                                "priority":"普通","mission_name":"买菠hahaha买萝haha买萝haha",
                                "deadline":"2020-06-20 08:00:00","status":0}
                                ,{"mission_id":14,"staff_id":10246,"staff_name":"爱荷华·亚历山大亚大爱华·亚历山大爱荷华·亚历山大爱荷华·亚历山大爱荷华·亚历山大","content":"买5斤萝卜回来","priority":"普通","mission_name":"买菠hahaha买萝haha买萝haha","deadline":"2020-06-20 08:00:00","status":0},{"mission_id":15,"staff_id":10246,"staff_name":"爱荷华·亚历山大亚大爱华·亚历山大爱荷华·亚历山大爱荷华·亚历山大爱荷华·亚历山大","content":"买5斤韭菜回来","priority":"普通","mission_name":"买菠hahaha买萝haha买萝haha","deadline":"2020-06-20 08:00:00","status":0},{"mission_id":16,"staff_id":10246,
                                      "staff_name":"爱荷华·亚历山大亚大爱华·亚历山大爱荷华·亚历山大爱荷华·亚历山大爱荷华·亚历山大",
                                      "content":"买5斤西瓜回来","priority":"普通","mission_name":"买菠hahaha买萝haha买萝haha",
                                      "deadline":"2020-06-21 14:09:34","status":0
                          }*/
                                {
                                    field: 'mission_id', title: 'MISSION ID', width: '15%',
                                    align: 'center'
                                },
                                {
                                    field: 'mission_name', title: 'MISSION NAME', width: '25%',
                                    align: 'center'
                                },

                                {
                                    field: 'priority', title: 'PRIORITY', align: 'center', width: '25%',
                                },
                                {
                                    field: 'deadline', title: 'DEADLINE', align: 'center', width: '25%',
                                }

                            ]]
                    });
                }, 'json')

            }

        }
    }
)
$('#dg').datagrid({
    onSelect: function (rowIndex, rowData) {
        document.getElementById("detailInformation").innerText = rowData.content
    }
});
$('#dg2').datagrid({
    onSelect: function (rowIndex, rowData) {
        document.getElementById("detailInformation").innerText = rowData.content
    }
});


function submitForm() {
    let name = document.getElementById("_easyui_textbox_input2").value
    let address = document.getElementById("_easyui_textbox_input3").value
    let email = document.getElementById("_easyui_textbox_input4").value
    $.post("/admin/modifyAdminAccount", {
        "name": name,
        "address": address,
        "email": email
    }, (res) => {
        if (res.code == '449') {
            alert(res.description)
            document.location = "/public/index.html"
        } else {
            alert(res.description)
            document.location.reload()
        }
    })
}

$('input.easyui-validatebox').validatebox({
    validateOnCreate: false,
    err: function (target, message, action) {
        var opts = $(target).validatebox('options');
        message = message || opts.prompt;
        $.fn.validatebox.defaults.err(target, message, action);
    }
});
$('#dg4').datagrid({
    onSelect: function (rowIndex, rowData) {
        staff_index_set.add(rowIndex)
        staff_id_set.add(rowData.id)
    },
    onUnselect: function (rowIndex, rowData) {
        staff_index_set.delete(rowIndex)
        staff_id_set.delete(rowData.id)
    },
    onSelectAll: function (rows) {
        let length = rows.length
        for (let i = 0; i < length; i++) {
            staff_index_set.add(i)
            $('#dg4').datagrid('selectRow', i)
        }

        for (const row of rows) {
            staff_id_set.add(row.id)
        }
    },
    onUnselectAll: function (rows) {
        let length = rows.length
        for (let i = 0; i < length; i++) {
            staff_index_set.delete(i)
            $('#dg4').datagrid('unselectRow', i)
        }

        for (const row of rows) {
            staff_id_set.delete(row.id)
        }
    },
});
$('#dg3').datagrid({
    onSelect: function (rowIndex, rowData) {
        cancelMissionList.add(`${rowData.staff_id}+${rowData.mission_id}`)
    },
    onUnselect: function (rowIndex, rowData) {
        cancelMissionList.delete(`${rowData.staff_id}+${rowData.mission_id}`)
    },
    onSelectAll: function (rows) {
        for (const row of rows) {
            cancelMissionList.add(`${row.staff_id}+${row.mission_id}`)
        }
    },
    onUnselectAll: function (rows) {
        for (const row of rows) {
            cancelMissionList.delete(`${row.staff_id}+${row.mission_id}`)
        }
    }
});
let cancel = function () {
    for (const cancelMissionListElement of cancelMissionList) {
        let staff_mission = cancelMissionListElement.split('+')
        $.post('/admin/cancelAssignedMission',
            {
                'staff_id': staff_mission[0],
                'mission_id': staff_mission[1]
            }, (res) => {
                if (res.code == '233') {
                    alert(res.description)
                    document.location.reload()
                } else {
                    alert(res.description)
                }

            }, 'json')
    }
}


$('#dg5').datagrid({
    onSelect: function (rowIndex, rowData) {
        mission_index_set.add(rowIndex)
        mission_id_set.add(rowData.mission_id)
    },
    onUnselect: function (rowIndex, rowData) {
        mission_index_set.delete(rowIndex)
        mission_id_set.delete(rowData.mission_id)
    },
    onSelectAll: function (rows) {
        let length = rows.length
        for (let i = 0; i < length; i++) {
            mission_index_set.add(i)
            $('#dg5').datagrid('selectRow', i)
        }

        for (const row of rows) {
            mission_id_set.add(row.mission_id)

        }
    },
    onUnselectAll: function (rows) {
        let length = rows.length
        for (let i = 0; i < length; i++) {
            mission_index_set.delete(i)
            $('#dg5').datagrid('unselectRow', i)
        }

        for (const row of rows) {
            mission_id_set.delete(row.mission_id)
        }
    },
    onAfterEdit: function (rowIndex, rowData, changes) {
        $.post('/admin/appendMission',
            {
                "content": rowData.content,
                "priority": rowData.priority,
                "mission_name": rowData.mission_name,
                "deadline": rowData.deadline,
                "mission_type": rowData.mission_type
            }
            , (res) => {
                if (res.code == '449') {
                    alert(res.description)
                    document.location = "/public/index.html"
                } else {
                    rowData.mission_id = res.data
                    alert(res.description)
                    document.location.reload()
                }
            }, 'json')
    },
    onBeforeEdit: function (rowIndex, rowData) {
        rowData.mission_id = 'AUTO'
    }
});

let refreshDetail = function () {

    let staffList = "";
    for (const staffListElement of staff_id_set) {
        staffList = staffList + staffListElement + ","
    }
    let missionList = "";
    for (const missionListElement of mission_id_set) {
        missionList = missionList + missionListElement + ","
    }
    if (staff_id_set.size > 0) {
        if (mission_id_set.size > 0) {
            confirm()
        } else {
            alert("you must choose one mission at least")
        }
    } else {
        alert("you must choose one staff at least")
    }
    document.getElementById("detailInformation").innerText = `you choose to assign \nmission list:\n${missionList} \nto staff list:\n ${staffList}\n`
}

let confirm = function () {
    for (const staff_id of staff_id_set) {
        for (const mission_id of mission_id_set) {
            $.post('/admin/assignMission', {
                "staff_id": staff_id,
                "mission_id": mission_id
            }, (res) => {
                if (res.code == '461') {
                    alert(`${staff_id},assign to ${mission_id}:${res.description}`)
                    let span = document.createElement("span")
                    span.style.color = "#cc3333"
                    span.innerText = `********\n【mission:${mission_id}】assign to【staff:${staff_id}】:【${res.description}】\n`
                    document.getElementById("detailInformation").appendChild(span)
                } else {
                    let span = document.createElement("span")
                    span.style.color = '#009966'
                    span.innerText = `********\n【mission:${mission_id}】assign to【staff:${staff_id}】:【${res.description}】\n`
                    document.getElementById("detailInformation").appendChild(span)
                }


            }, 'json')
        }
    }
}
let editIndex = undefined;

function missionListEndEditing() {
    if (editIndex == undefined) {
        return true
    }
    if ($('#dg5').datagrid('validateRow', editIndex)) {
        var ed = $('#dg5').datagrid('getEditor', {index: editIndex, field: 'productid'});
        $('#dg5').datagrid('endEdit', editIndex);
        editIndex = undefined;
        return true;
    } else {
        return false;
    }
}

function missionListCreate() {
    if (missionListEndEditing()) {
        $('#dg5').datagrid('appendRow', {status: 'P'});
        editIndex = $('#dg5').datagrid('getRows').length - 1;
        $('#dg5').datagrid('selectRow', editIndex)
            .datagrid('beginEdit', editIndex);
    }
}

function removeMissionListEnd() {
    if (editIndex == undefined) {
        return
    }
    $('#dg5').datagrid('cancelEdit', editIndex)
        .datagrid('deleteRow', editIndex);
    editIndex = undefined;
}

function acceptCreate() {
    if (missionListEndEditing()) {
        editIndex = $('#dg5').datagrid('getRows').length - 1;
        $('#dg5').datagrid('acceptChanges');
    }
}

function rejectCreate() {
    $('#dg5').datagrid('rejectChanges');
    editIndex = undefined;
}


window.addEventListener('load',()=>{
    document.getElementById("logout").innerText=Cookies.get("staffname")
    setInterval(()=>{
        document.getElementById("time").innerText=new Date().toLocaleString()
    },1000)
})
$.fn.datebox.defaults.formatter = function(date){
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    var d = date.getDate();
    return `${y}-${m}-${d}`
}


$.fn.datebox.defaults.parser=function (s) {
    var t = Date.parse(s);
    if (!isNaN(t)) {
        return new Date(t);
    } else {
        return new Date();
    }
}
